<template>
  <div class="dashboard">
    <section class="dashboard-hero">
      <div class="dashboard-hero__text">
        <span class="dashboard-hero__eyebrow">学生门户</span>
        <h2 class="dashboard-hero__title">你好，{{ userName }}</h2>
        <p class="dashboard-hero__desc">
          欢迎来到排课管理系统，及时掌握课程安排与校园动态，开启高效的学习与生活。
        </p>
        <div class="dashboard-hero__meta" v-if="heroChips.length">
          <span v-for="chip in heroChips" :key="chip" class="dashboard-chip">{{ chip }}</span>
        </div>
      </div>
      <div class="dashboard-hero__badge">
        <el-icon><UserFilled /></el-icon>
      </div>
    </section>

    <el-card class="dashboard-card" shadow="hover">
      <template #header>
        个人信息
      </template>
      <div class="info-grid">
        <div v-for="item in profileItems" :key="item.label" class="info-grid__item">
          <span class="info-grid__label">{{ item.label }}</span>
          <span class="info-grid__value">{{ item.value }}</span>
        </div>
      </div>
    </el-card>

    <div class="dashboard-grid">
      <el-card
        v-for="item in reminders"
        :key="item.title"
        class="dashboard-card tips-card"
        shadow="hover"
        @click="handleCardClick(item.page)"
      >
        <div class="tips-card__icon">
          <el-icon><component :is="item.icon" /></el-icon>
        </div>
        <h3 class="tips-card__title">{{ item.title }}</h3>
        <p class="tips-card__desc">{{ item.description }}</p>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { computed, markRaw } from 'vue'
import { UserFilled, Calendar, EditPen, Notification } from '@element-plus/icons-vue'

const emit = defineEmits(['page-change'])

const user = JSON.parse(localStorage.getItem('user') || '{}')

const userName = computed(() => user?.stuName || '同学')

const heroChips = computed(() => {
  const chips = []
  if (user?.stuDept) chips.push(`院系 · ${user.stuDept}`)
  if (user?.stuNo) chips.push(`学号 · ${user.stuNo}`)
  if (user?.stuPhone) chips.push(`联系电话 · ${user.stuPhone}`)
  return chips
})

const profileItems = computed(() => [
  { label: '学号', value: user?.stuNo || '-' },
  { label: '姓名', value: user?.stuName || '-' },
  { label: '院系', value: user?.stuDept || '-' },
  { label: '手机号', value: user?.stuPhone || '-' },
  { label: '邮箱', value: user?.stuEmail || '-' },
  { label: 'QQ', value: user?.stuQq || '-' }
])

const reminders = [
  {
    title: '课程提醒',
    description: '及时关注课表更新及调课通知，合理安排每日学习。',
    icon: markRaw(Calendar),
    page: 'student-reminders'
  },
  {
    title: '资料维护',
    description: '保持联系方式与院系信息最新，确保重要消息不错过。',
    icon: markRaw(EditPen),
    page: 'student-profile'
  },
  {
    title: '学习通知',
    description: '关注班级公告、作业发布与考试安排，提前做好准备。',
    icon: markRaw(Notification),
    page: 'student-notices'
  }
]

const handleCardClick = (page) => {
  emit('page-change', page)
}
</script>

<style scoped>
.dashboard {
  max-width: 1200px;
  margin: 0 auto;
}

/* Hero Section */
.dashboard-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 40px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 16px;
  color: white;
  margin-bottom: 32px;
  box-shadow: 0 10px 40px rgba(102, 126, 234, 0.3);
}

.dashboard-hero__text {
  flex: 1;
}

.dashboard-hero__eyebrow {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  opacity: 0.9;
  margin-bottom: 8px;
}

.dashboard-hero__title {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 12px;
}

.dashboard-hero__desc {
  font-size: 16px;
  line-height: 1.6;
  opacity: 0.95;
  margin-bottom: 16px;
}

.dashboard-hero__meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.dashboard-chip {
  display: inline-block;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  backdrop-filter: blur(10px);
}

.dashboard-hero__badge {
  flex-shrink: 0;
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  font-size: 48px;
  backdrop-filter: blur(10px);
}

/* Dashboard Card */
.dashboard-card {
  border-radius: 16px;
  margin-bottom: 24px;
  border: none;
  overflow: hidden;
}

.dashboard-card :deep(.el-card__header) {
  background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
  border-bottom: 2px solid #e9ecef;
  font-weight: 600;
  font-size: 18px;
  color: #2c3e50;
}

/* Info Grid */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 24px;
}

.info-grid__item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-grid__label {
  font-size: 13px;
  color: #6c757d;
  font-weight: 500;
}

.info-grid__value {
  font-size: 16px;
  color: #2c3e50;
  font-weight: 600;
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

/* Tips Card */
.tips-card {
  text-align: center;
  padding: 32px 24px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.tips-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.tips-card:hover::before {
  opacity: 1;
}

.tips-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.tips-card__icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 16px;
  color: white;
  font-size: 32px;
  transition: all 0.3s ease;
}

.tips-card:hover .tips-card__icon {
  transform: scale(1.1) rotate(5deg);
}

.tips-card__title {
  font-size: 20px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 12px;
}

.tips-card__desc {
  font-size: 14px;
  color: #6c757d;
  line-height: 1.6;
}
</style>
